package com.lkd.handler;

import com.lkd.business.MsgHandler;
import com.lkd.common.VMSystem;
import com.lkd.config.TopicConfig;
import com.lkd.contract.TaskCompleteContract;
import com.lkd.emq.Topic;
import com.lkd.feign.VMService;
import com.lkd.service.VendingMachineService;
import com.lkd.utils.JsonUtil;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 工单完成处理
 */

@Component
@Topic(TopicConfig.VMS_COMPLETED_TOPIC)
public class TaskCompletedMsgHandler implements MsgHandler {

    @Autowired
    private VendingMachineService vendingMachineService;

    @Override
    public void process(String jsonMsg) throws IOException {
        TaskCompleteContract contract = JsonUtil.getByJson(jsonMsg, TaskCompleteContract.class);
        //如果是投放工单  改为运营工单
        if (contract.getTaskType() == VMSystem.TASK_TYPE_DEPLOY) {
            vendingMachineService.updateStatus(contract.getInnerCode(), VMSystem.VM_STATUS_RUNNING);
        }

        //如果是撤机工单  改为撤机工单
        if (contract.getTaskType() == VMSystem.TASK_TYPE_REVOKE) {
            vendingMachineService.updateStatus(contract.getInnerCode(), VMSystem.VM_STATUS_REVOKE);
        }

    }
}
